
package com.principle.builder;

import java.util.ArrayList;

public class Director {
    private ArrayList<String> sequence = new ArrayList<String>();

    private BenzBuilder benzBuilder = new BenzBuilder();
    private BMWBuilder bmwBuilder = new BMWBuilder();

    // =================================================
    /**
     * A 类型奔驰
     */
    public BenzModel getABenzModel() {
        this.sequence.clear(); // 一定要清空
        this.sequence.add("start");
        this.sequence.add("stop");
        this.benzBuilder.setSequence(this.sequence);
        return (BenzModel) this.benzBuilder.getCarModel();
    }

    /**
     * B 类型奔驰
     */
    public BenzModel getBBenzModel() {
        this.sequence.clear(); // 一定要清空
        this.sequence.add("engine boom");
        this.sequence.add("start");
        this.sequence.add("stop");
        this.benzBuilder.setSequence(this.sequence);
        return (BenzModel) this.benzBuilder.getCarModel();
    }

    /**
     * ... 类型奔驰
     */

    // =================================================
    /**
     * A 类型宝马
     */
    public BMWModel getABMWModel() {
        this.sequence.clear();
        this.sequence.add("start");
        this.sequence.add("stop");
        this.bmwBuilder.setSequence(this.sequence);
        return (BMWModel) this.bmwBuilder.getCarModel();
    }

    /**
     * B 类型宝马
     */
    public BMWModel getBBMWModel() {
        this.sequence.clear();
        this.sequence.add("engine boom");
        this.sequence.add("start");
        this.sequence.add("stop");
        this.bmwBuilder.setSequence(this.sequence);
        return (BMWModel) this.bmwBuilder.getCarModel();
    }

    /**
     * ... 类型宝马
     */
    // =================================================
    
    /**
     * 客户端调用
     * @param args
     */
    public static void main(String[] args) {
        Director director = new Director();
        
        BenzModel benzModel = director.getABenzModel();
        benzModel.run();
        
        System.out.println("=================================");
        
        benzModel = director.getBBenzModel();
        benzModel.run();
        
        System.out.println("===Benz===================BMW====");
        
        BMWModel bmwModel = director.getABMWModel();
        bmwModel.run();
        
        System.out.println("=================================");
        
        bmwModel = director.getBBMWModel();
        bmwModel.run();
    }
}
